import {
  requst_get_getPicInfo,
  requst_get_getConfigInfo
} from '../../utils/api.js'
import {
  adList
} from "../../utils/adConfig.js";
var app= getApp();
Page({
  data: {
    wallpaper: [], //壁纸
    bannerInfos: [], //轮播
    hiddenTop: true,
    isLastPage1: false,
    current: 1,
    pageSize: 20,
    bannerVideo: adList().bannerVideo,
    configInfo:{},
    bannerImage:"https://mmbiz.qpic.cn/sz_mmbiz_png/0ZUPFs8FEgsBC0h6Xpa3zg2DibuwKgyeUo4otc5MtymuTQPKiaorP7t4uGic4ia0vlgIc8YxzXkItfyofd476kPuLw/640?wx_fmt=png"
  },
  onLoad: function () {
    this.getPicList();
   
    app.loginWx();
    
  },
  onReady: function () {},
  onShow: function () {
    this.getConfig();
  },


  onHide: function () {},
  onUnload: function () {},
  onPageScroll: function (t) {
    t.scrollTop > 400 ? this.setData({
      hiddenTop: false
    }) : this.setData({
      hiddenTop: true
    });
  },
  getConfig:function(){
    var that = this;
    const params = {
    }
    requst_get_getConfigInfo(params).then(res => {
      that.setData({
        configInfo: res.data
      })
      app.globalData.version = res.data.version
      console.log('ccc',configInfo.bannerImage&&configInfo.bannerImage.indexof('http')!=-1&&configInfo.version==1)
    }).catch(err => {
    })
  },
  getPicList: function () {
    var that = this;
    const params = {
      picCategory: 1,
      groupId: 0,
      current: that.data.current,
      size: that.data.pageSize
    }
    requst_get_getPicInfo(params).then(res => {
      if (that.data.current == res.data.pages) {
        that.setData({
          isLastPage1: true,
        })
      }
      that.setData({
        wallpaper: that.data.wallpaper.concat(res.data.records)
      })
      wx.stopPullDownRefresh();
    }).catch(err => {
      wx.stopPullDownRefresh();
    })
  },

  onPullDownRefresh: function () {
    this.setData({
        current: 1,
        wallpaper: [],
        isLastPage1: false,

      }),
      this.getPicList();
  },

  onReachBottom: function () {
    if (!this.data.isLastPage1) {
      this.setData({
        current: this.data.current + 1,
      })
      this.getPicList();
    }
  },
  onShareAppMessage: function () {
    return {
      title: "手机壁纸、渣男壁纸、高清壁纸、情侣头像、男生女生头像！",
      path: "/pages/wallpaper/index"

    };
  },
  onShareTimeline: function () {
    return {
      title: "好友推荐你一个优质头像壁纸库！",
      path: "/pages/wallpaper/index"
    };
  },
  intowallpaper: function (t) {
    var type = t.currentTarget.dataset.type;
    wx.navigateTo({
      url: '/pages/wallpaper_page/index?type=' + type,
    })
  },
  goToPhotoInfo: function (t) {
    var e = t.currentTarget.dataset.src;
    var picid = t.currentTarget.dataset.picid;
    var needcount = t.currentTarget.dataset.needcount;
    wx.navigateTo({
      url: "../photo/photo?src=" + e + "&picId=" + picid + "&needcount=" + needcount,
    });
  },
  bindDetail: function (t) {
    var src = t.currentTarget.dataset.url
    var picId = t.currentTarget.dataset.id
    console.log("t",t.currentTarget.dataset)
    wx.navigateTo({
      url: "/pages/detail/detail?picId=" + picId+"&picPath=" + src,
    });
  },
  goTop: function (t) {
    wx.pageScrollTo ? wx.pageScrollTo({
      scrollTop: 0
    }) : wx.showModal({
      title: "提示",
      content: "当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。"
    });
  },
  //跳转至webview 页面
  intowebpage:function(){
    var that =this;
wx.navigateTo({
  url: '/pages/webpage/index?src='+that.data.configInfo.bannerpath,
})
  }
});